package sjgl.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONArray;
import sjgl.agent.IsjAgent;
import common.Const;
import common.MyUtils;
import common.BaseClasses.CommonAction;
import common.BaseClasses.util.IocUtil;
 
public class SjAction extends CommonAction{
    private IsjAgent sjAgentImpl;
	private  Map<Object, Object> resultMap;
    public SjAction(){
    	try {
			this.sjAgentImpl=(IsjAgent) IocUtil.getIocImpl("sjgl/ioc/ioc-sj.xml","sjAgentImpl");
		} catch (Throwable e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }
    /**
     * 新增一个事件
     * @return
     */
    public String Addsj(){
    	Map map=new HashMap();
    	map.put("eve_cd",MyUtils.getUUID());
    	map.put("eve_nm",getParameter("eve_nm"));
    	map.put("rec_dt",getParameter("rec_dt"));
    	map.put("rec_nm", getParameter("rec_nm"));
    	map.put("eve_dt", getParameter("eve_dt"));
    	map.put("eve_addr",getParameter("eve_addr"));
    	map.put("water_deg",getParameter("water_deg"));
    	map.put("eve_gs",getParameter("eve_gs"));
    	map.put("eve_type",getParameter("eve_type"));
    	map.put("eve_method",getParameter("eve_method"));
    	map.put("eve_dre", getParameter("eve_dre"));
    	map.put("eve_xgpg",getParameter("eve_xgpg"));
    	System.out.println(map);
    	sjAgentImpl.insert(map);
    	return "success";
    }
    /**
     * 到达事件管理的jsp页面的action
     * @return
     */
    public String toSjglPage(){
    	Map map=new HashMap();
    	paramMap.put("returnPageName", "toSjFenYePage");
    	resultMap=sjAgentImpl.findSjByPage(1,getIntParameter("pageSize"),map);
    	setPageParam(resultMap);
    	return "toSjglPage";
    }
    /**
     * 到达新建事件的jsp页面
     * @return
     */
    public String toXjSjPage(){
    	Map map=new HashMap();
    	paramMap.put("returnPageName", "toXjSjFenYePage");
    	resultMap=sjAgentImpl.findSjByPage(1, getIntParameter("pageSize"), map);
    	System.out.println(resultMap);
    	setPageParam(resultMap);
    	return "toXjSjPage";
    }
    /**
     * 点击分页条下的数字触发的分页action
     * @return
     */
    public String findSjByPage(){
    	//分页条件
    	paramMap.put("returnPageName", getParameter("returnPageName"));
    	paramMap.put("startTime",getParameter("startTime",""));
    	paramMap.put("endTime", getParameter("endTime",""));
    	paramMap.put("eventName", getParameter("eventName",""));
    	Map map=new HashMap();
    	map.put("startTime", getParameter("startTime", ""));
    	map.put("endTime", getParameter("endTime", ""));
    	map.put("eventName", getParameter("eventName",""));
    	resultMap=sjAgentImpl.findSjByPage(pageBean.getCurrentPage(), pageBean.getPageSize(), map);
    	System.out.println("分页得到的结果"+resultMap);
        setPageParam(resultMap);
    	return getParameter("returnPageName");
    }
    /**
     * 根据事件的主键批量或者单独删除一个事件
     */
    public void DeleteSj(){
    	String eveCdArr=getParameter("eveCdArr");
    	System.out.println(getParameter("eveCdArr"));
    	String result=sjAgentImpl.deleteSj(eveCdArr);
    	System.out.println(result);
    	writeStringToResponse(result);
    }
    /**
     * 根据主键查找一个事件
     */
    public void findSjById(){
    	Map map=new HashMap();
    	System.out.println(getParameter("uuid"));
    	map.put("eve_cd", getParameter("uuid"));
    	List list=sjAgentImpl.seleteSjById(map);
    	System.out.println("--------------"+list);
    	writeStringToResponse(JSONArray.fromObject(list));
    }
    /**
     * 根据日期查询，或者事件名称查询事件
     */
    public String searchSj(){
    	Map map=new HashMap();
    	map.put("startTime", getParameter("startTime"));
    	map.put("endTime",getParameter("endTime"));
    	map.put("eventName", getParameter("eventName"));
    	//将查询条件存入到分页标签里面
    	paramMap.put("returnPageName", getParameter("returnPageName"));
    	paramMap.put("startTime", getParameter("startTime"));
    	paramMap.put("endTime", getParameter("endTime"));
    	paramMap.put("eventName", getParameter("eventName"));
    	System.out.println("------------"+getIntParameter("pageSize"));
    	resultMap=sjAgentImpl.findSjByPage(1, getIntParameter("pageSize"), map);
    	System.out.println("-------------"+resultMap);
        setPageParam(resultMap);
    	return getParameter("returnPageName");
    }
    /**
     * 根据事件的id更新一个事件
     * @return
     */
    public String updateSj(){
    	Map map=new HashMap();
    	map.put("eve_cd",getParameter("eve_cd"));
    	map.put("eve_nm",getParameter("eve_nm"));
    	map.put("rec_dt",getParameter("rec_dt"));
    	map.put("rec_nm", getParameter("rec_nm"));
    	map.put("eve_dt", getParameter("eve_dt"));
    	map.put("eve_addr",getParameter("eve_addr"));
    	map.put("water_deg",getParameter("water_deg"));
    	map.put("eve_gs",getParameter("eve_gs"));
    	map.put("eve_type",getParameter("eve_type"));
    	map.put("eve_method",getParameter("eve_method"));
    	map.put("eve_dre", getParameter("eve_dre"));
    	map.put("eve_xgpg",getParameter("eve_xgpg"));
    	System.out.println(map);
    	sjAgentImpl.updateSj(map);
    	return "success";
    }
	public Map<Object, Object> getResultMap() {
		return resultMap;
	}
	public void setResultMap(Map<Object, Object> resultMap) {
		this.resultMap = resultMap;
	}
	public IsjAgent getSjAgentImpl() {
		return sjAgentImpl;
	}
	public void setSjAgentImpl(IsjAgent sjAgentImpl) {
		this.sjAgentImpl = sjAgentImpl;
	}
}
